Repository navigation
[CPU] Fix strided half-precision GEMM dimensions in BNNS and simd_gemm - #4947
Merged
Merged
Conversation
Yunt1
force-pushed
the
fix/4739-cpu-segmented-mm-half
branch
from
November 23, 2026 02:14
4f4b3b1 to
8783720
Compare
zcbenz
marked this pull request as ready for review
November 24, 2026 08:32
zcbenz
force-pushed
the
fix/4739-cpu-segmented-mm-half
branch
from
November 24, 2026 08:32
8783720 to
101367e
Compare
zcbenz
approved these changes
Nov 24, 2026
rcfa
pushed a commit
to cubiculum-ai/mlx
that referenced
this pull request
Nov 26, 2026
ml-explore#4947) Co-authored-by: Yunt1 <Yunt1@users.noreply.github.com> Co-authored-by: Cheng <git@zcbenz.com> Ported: osaurus-ai/mlx PR 26 already passes lda and ldb to simd_gemm (the fix for ml-explore/mlx issue 4739). This commit adds what PR 26 did not: ldc for the output, and the BNNS dimensions. The Highway path (simd_low_precision_gemm.h) passes ldc to its simd_gemm call too. tests/blas_tests.cpp keeps PR 26's test and adds Apple's. (cherry picked from commit c3ff43b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4739 (follow-up to #4924 with
simd_gemmfixed for Linux/Windows as well).Summary
mlx/backend/cpu/gemms/bnns.cpp(macOS):BNNSNDArrayDescriptor::sizeforBNNSDataLayoutRowMajorMatrixwas set to{lda, (M * K) / lda}and{ldb, (K * N) / ldb}instead of the actual logical matrix dimensions{cols, rows}. SetiA_desc.sizeto{a_transposed ? M : K, a_transposed ? K : M},iB_desc.sizeto{b_transposed ? K : N, b_transposed ? N : K}, ando_desc.strideto{1, ldc}.mlx/backend/cpu/gemms/simd_gemm.h,simd_bf16.cpp,simd_fp16.cpp(Linux/Windows): Pass and uselda,ldb,ldcinload_blockand output store instead of assuming contiguousK/Nstrides.tests/blas_tests.cpp: Addtest segmented_mm float16 and bfloat16covering all four transpose combinations.Testing
-DMLX_BUILD_METAL=OFF -DMLX_BUILD_TESTS=ON):./build/tests/tests -sf="*blas_tests.cpp"-> 2/2 test cases passed (31/31 assertions).simd_bf16.cppandsimd_fp16.cppwithclang++ -fsyntax-only.